package com.hnust.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnust.entity.SensorData;
import com.hnust.entity.dto.SensorDataDto;
import com.hnust.entity.dto.SensorDataDto1;
import com.hnust.service.SensorDataService;
import com.hnust.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/4/21
 * 描述：
 */
@Slf4j
@RestController
@CrossOrigin("*")
    @RequestMapping("/sensor_data")
public class SensorDataController {
    @Autowired
    private SensorDataService sensorDataService;

    @GetMapping("/search")//时间只有年月日
    public R<Page<SensorDataDto>> sensorDataSearch(
            int page,int pageSize,String beginTime,String endTime,
            String position,//以逗号隔开的四个位置代码
            String uid)
    {
        log.info("根据时间段搜索传感器数据:{},{},{},{}",page,pageSize,beginTime,endTime);
        Page<SensorDataDto> pageInfo=sensorDataService.sensorDataSearch(
                page,pageSize,beginTime,endTime,position,uid
        );
        return R.success(pageInfo);
    }

    @GetMapping("/show")
    public R<List<SensorData>> sensorDataShow(
        String positionId
    ){
        log.info("传入positionId为:{}",positionId);
        List<SensorData> sensorDatas = sensorDataService.sensorDataShow(positionId);
        return R.success(sensorDatas);
    }
}
